package com.rdExpenses.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.base.common.persistence.Page;
import com.base.common.service.CrudService;
import com.base.common.utils.StringUtils;
import com.rdExpenses.dao.ExpenseAssignMapper;
import com.rdExpenses.model.ExpenseAssign;
import com.rdExpenses.model.ExpenseInfo;
import com.rdExpenses.service.ExpenseAssignService;

@Service
public class ExpenseAssignServiceImpl extends CrudService<ExpenseAssignMapper, ExpenseAssign> implements
		ExpenseAssignService {

	public boolean saveExpenseAssign(ExpenseAssign expenseAssign) throws Exception {
		this.saveOrUpdate(expenseAssign);
		return true;
	}

	public List<ExpenseAssign> findExpenseAssignListByUserId(String userId) throws Exception {
		Map<String, String> params = new HashMap<String, String>();
		params.put("userId", userId);
		String sql = "SELECT t.id,t.title,t.type,t.expense,case t.status  when '0' then '未处理' when '1' then '已提交'  else '已审批' end as status,t.user_id,t.content "
				+ "from expense_assign t where t.user_id = #{userId} ";

		// if (StringUtils.isNotEmpty(status) && !status.equals("-1")) {
		// params.put("status", status);
		// sql += " and t.status = #{status}";
		// }
		List<ExpenseAssign> list = this.getList(sql, ExpenseAssign.class, params);
		return list;
	}
	
	public ExpenseAssign findExpenseAssignById(String id) throws Exception {
		return this.get(id);
	}
}
